function out = GetRollingAverage(X,Y,xpoints,LogYes,plusminus,TruncateFirstPM)
if nargin <3
    LogYes = 1;
    Plots = 1;
    xpoints = [-3:.5:1.5];
    plusminus = .5;
    TruncateFirstPM = 0;
end
ttable = xlsread('Ttable.xlsx');
% Create Logged X Vector
if LogYes
    idx = find(X==0);
    X(idx) = [];
    Y(idx) = [];
    X = log10(X);
end


for kk = 1:length(xpoints)
    if (kk == 1) & LogYes & TruncateFirstPM
        PlusMinusLow = .1; % Set to only go as low as ABM (with 40x40 graph) will allow
    else
        PlusMinusLow = plusminus;
    end
    ind = (X>=(xpoints(kk)-PlusMinusLow)) & (X<(xpoints(kk)+plusminus));
    nsize(kk) = sum(ind);
    WinsVector(kk) = sum(Y(ind)==1)/nsize(kk)*100;
    StandardError(kk) = std(Y(ind))/sqrt(nsize(kk))*100;
    if nsize(kk) < 2
        tvalue(kk) = nan;
    elseif nsize(kk) > 30;
        tvalue(kk) = ttable(31,4); % 95% CI, alpha/2 = .025, 4th col
    else
        tvalue(kk) = ttable(nsize(kk),4); % 95% CI, alpha/2 = .025, 4th col
    end
    WinsVectorHigh(kk) = WinsVector(kk)+tvalue(kk)*StandardError(kk);
    WinsVectorLow(kk) = WinsVector(kk)-tvalue(kk)*StandardError(kk);
end

% OutputVariable
out.X = xpoints;
out.Y = WinsVector;
out.CIlow= WinsVectorLow;
out.CIhigh= WinsVectorHigh;
out.nsize = nsize;

end
